// admin/pages/useradmin/useradmin.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabs: ['用户管理', '活动管理','参数设置'],
    tabIndex: 0,
    clslist:[
      {
        id:0,
        color:"Gainsboro",
        url:"static/3.png",
        name:"管理员"
      },
      {
        id:1,
        color:"Gainsboro",
        url:"static/3.png",
        name:"普通用户"
      }
    ],
    datelist:[
      {
        id:"10",
        name:"c+++++",
        checked:false
      }
    ],
    thisi:-1,
    thiscolor:"",
    checks:false,
    array: [20, 30, 40, 50,60,70,80,90],
    index:0,
    tab34checks:false,
    tab33checks:false,
    tab32checks:false,
    tab31checks:false,
    tabshow1:false,
    tabshow2:false,
    tabshow3:false,
    nums:0
  },
  qr(){
    var index = this.data.index
    var das = this.data.array[index]
    wx.showModal({
      title:'提示',
      content:'请确认是否设置',
      success:function(res)
      {
        if(res.cancel)
        {
          //点击取消按钮
        }else if(res.confirm)
        {
          getApp().helper({
            url: getApp().globalData.urlpath + '/weixin/qr',
            data: {
              das:das
            },
            success(res) {
              if(res.data.ret == "True"){
              
               
              }
              else if(res.data.ret == "F2"){
                wx.showToast({
                  title: '错误',
                  icon:"error",
                  duration:1500
                })
                
              }
                
            },
            fail() {
              wx.showToast({
                title: '连接服务器失败',
                image: '/static/error.png',
                duration: 1500
              });
            }
          });
        }
      }
    })
  },
  redo(){
    wx.showModal({
      title:'提示',
      content:'请确认是否重启',
      success:function(res)
      {
        if(res.cancel)
        {
          //点击取消按钮
        }else if(res.confirm)
        {
          getApp().helper({
            url: getApp().globalData.urlpath + '/weixin/redo',
            data: {
              
            },
            success(res) {
              if(res.data.ret == "True"){
              
               
              }
              else if(res.data.ret == "F2"){
                wx.showToast({
                  title: '错误',
                  icon:"error",
                  duration:1500
                })
                
              }
                
            },
            fail() {
              wx.showToast({
                title: '连接服务器失败',
                image: '/static/error.png',
                duration: 1500
              });
            }
          });
        }
      }
    })
    
  },
  del(){
    var lists = this.data.datelist
    var checks = false
    var li = []
    for(var i = 0; i < lists.length; i ++ )
    {
      if(lists[i].checked) 
      {
        checks = true
        li.push(lists[i])
      }
    }
    if(checks){
      getApp().helper({
        url: getApp().globalData.urlpath + 'weixin/dels',
        data: {
          li:li
        },
        success(res) {
          wx.showToast({
            title: '删除成功',
            icon:'success',
            duration: 1500
          });
          that.anxia()
        },
        fail(res) {
          wx.showToast({
            title: '连接服务器失败',
            image: '/static/error.png',
            duration: 1500
          });
        }
      });
    }
    else{
      wx.showToast({
        title: '至少选一个',
        icon: 'error',
        duration: 1500
      });
    }
  },
  pow(){
  var lists = this.data.datelist
  var checks = false
  var li = []
  for(var i = 0; i < lists.length; i ++ )
  {
    if(lists[i].checked) 
    {
      checks = true
      li.push(lists[i])
    }
  }
  if(checks){
    getApp().helper({
      url: getApp().globalData.urlpath + 'weixin/powt',
      data: {
        li:li
      },
      success(res) {
        wx.showToast({
          title: '权限提升成功',
          icon:'success',
          duration: 1500
        });
        that.anxia()
      },
      fail(res) {
        wx.showToast({
          title: '连接服务器失败',
          image: '/static/error.png',
          duration: 15000
        });
      }
    });
  }
  else{
    wx.showToast({
      title: '至少选一个',
      icon: 'error',
      duration: 1500
    });
  }
  },
  pows(){
    var lists = this.data.datelist
    var checks = false
    var li = []
    for(var i = 0; i < lists.length; i ++ )
    {
      if(lists[i].checked) 
      {
        checks = true
        li.push(lists[i])
      }
    }
    if(checks){
      getApp().helper({
        url: getApp().globalData.urlpath + 'weixin/pows',
        data: {
          li:li
        },
        success(res) {
          wx.showToast({
            title: '权限提升成功',
            icon:'success',
            duration: 1500
          });
          that.anxia()
        },
        fail(res) {
          wx.showToast({
            title: '连接服务器失败',
            image: '/static/error.png',
            duration: 15000
          });
        }
      });
    }
    else{
      wx.showToast({
        title: '至少选一个',
        icon: 'error',
        duration: 1500
      });
    }
    },
  bindPickerChange: function (e) {
    this.setData({
      index: e.detail.value
    })
  },
  clickmes(e){
    this.setData({
      checks: !this.data.checks
    })
    var checks = this.data.checks
    var lists  = this.data.datelist
    for(var i = 0; i < lists.length; i ++ )
    {
      lists[i].checked = checks
    }
    this.setData({
        datelist:lists
      })
  },
  onTabClick(e) {
    let id = e.currentTarget.id
    let that = this
    this.setData({
      tabIndex: id,
    })
    if(id == 2)
    {
      getApp().helper({
        url: getApp().globalData.urlpath + '/weixin/getunck',
        data: {
        },
        success(res) {
          that.setData({
            nums:res.data.nums
          })
        },
        fail(res) {
          wx.showToast({
            title: '连接服务器失败',
            image: '/static/error.png',
            duration: 1500
          });
        }
      });
    }
   
  },
  anxia(e){
    var id = e.currentTarget.dataset.id
    var lists = this.data.clslist
    var lasti = this.data.thisi
    var lastcolor = this.data.thiscolor
    var that = this
    if(lastcolor.length!=0 && lasti != -1)
    {
      lists[lasti].color = lastcolor
      that.setData({
        clslist:lists
      })
    }
    for(var i = 0; i < lists.length; i ++ )
    {
      if(lists[i].id == id)
      {
        var newcolor = lists[i].color
        lists[i].color = "BlanchedAlmond"
        that.setData({
          clslist:lists,
          thisi:i,
          thiscolor:newcolor
        })
      }
    }
    getApp().helper({
      url: getApp().globalData.urlpath + '/weixin/getuserdata',
      data: {
        id: id,
      },
      success(res) {
        that.setData({
          datelist:res.data.datelist
        })
      },
      fail(res) {
        wx.showToast({
          title: '连接服务器失败',
          image: '/static/error.png',
          duration: 1500
        });
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})